<template>
    <div class="text-center margin-top">
        loading...
    </div>
</template>

<script>
    import website from "/src/config/website";
    import {search, click} from '/src/request/api/nav';

    export default {
        name: "link",
        components: {},
        data() {
            return {}
        },
        created() {
            this.init();
        },
        mounted() {

        },
        methods: {
            init() {
                let that = this,
                    str = localStorage.getItem(website.goto),
                    obj = str && JSON.parse(str) ? JSON.parse(str) : {},
                    type = obj.type,
                    url = obj.url;
                if (!type) {
                    that.$message.warning('缺少必要参数:type');
                    return false;
                }
                if (!url) {
                    that.$message.warning('缺少必要参数:url');
                    return false;
                }
                // search
                if (type == 'search') {
                    search({
                        text: obj.text,
                        id: obj.id,
                    }).then(res => {
                        location.href = url;
                    }).catch(err => {
                        that.$message.error(err.msg || website.msg.error);
                    })
                }
                // link
                else if (type == 'quick' || type == 'bookmark') {
                    click({
                        //key: website.key,
                        uwid: obj.id,
                        wid: obj.wid,
                    }).then(res => {
                        location.href = url;
                    }).catch(err => {
                        that.$message.error(err.msg || website.msg.error);
                    })
                }
                // 其它
                else {
                    that.$message.warning('参数异常: type');
                }
            },
        }
    }
</script>

<style scoped>

</style>
